﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package reprise.css.propertyparsers {
    import reprise.css.*;
    import reprise.utils.*;
    import reprise.css.transitions.*;

    public class Background extends CSSPropertyParser {

        public static const REPEAT_REPEAT_XY:String = "repeat";
        public static const POSITION_BOTTOM:String = "bottom";
        public static const POSITION_TOP:String = "top";
        public static const IMAGE_TYPE_ANIMATION:String = "animation";
        public static const IMAGE_ALIASING_ANTIALIAS:String = "anti-alias";
        public static const POSITION_CENTER:String = "center";
        public static const SCALE9_TYPE_NONE:String = "none";
        public static const REPEAT_NO_REPEAT:String = "no-repeat";
        public static const ATTACHMENT_FIXED:String = "fixed";
        public static const GRADIENT_TYPE_LINEAR:String = "linear";
        public static const IMAGE_NONE:String = "none";
        public static const GRADIENT_TYPE_RADIAL:String = "radial";
        public static const IMAGE_ALIASING_ALIAS:String = "alias";
        public static const GRADIENT_TYPE_NONE:String = "none";
        public static const KNOWN_PROPERTIES:Object = {background:{parser:parseBackground}, backgroundImage:{parser:strToURLProperty}, backgroundColor:{parser:strToColorProperty, transition:ColorTransitionVO}, backgroundRepeat:{parser:strToStringProperty}, backgroundPosition:{parser:parseBackgroundPosition}, backgroundPositionX:{parser:strToIntProperty}, backgroundPositionY:{parser:strToIntProperty}, backgroundAttachment:{parser:strToStringProperty}, backgroundRenderer:{parser:strToStringProperty}, backgroundBlendMode:{parser:strToStringProperty}, backgroundGradient:{parser:parseBackgroundGradient}, backgroundGradientColors:{parser:parseBackgroundGradientColors, transition:ColorListTransitionVO}, backgroundGradientType:{parser:parseBackgroundGradientType}, backgroundGradientRatios:{parser:parseBackgroundGradientRatios, transition:NumericListTransitionVO}, backgroundGradientRotation:{parser:strToIntProperty}, backgroundScale9:{parser:parseBackgroundScale9}, backgroundScale9Type:{parser:parseBackgroundScale9Type}, backgroundScale9Rect:{parser:parseBackgroundScale9Rect}, backgroundScale9RectTop:{parser:strToIntProperty}, backgroundScale9RectRight:{parser:strToIntProperty}, backgroundScale9RectBottom:{parser:strToIntProperty}, backgroundScale9RectLeft:{parser:strToIntProperty}, backgroundImageType:{parser:parseBackgroundImageType}, backgroundAnimationControl:{parser:parseBackgroundAnimationControl}, backgroundImagePreload:{parser:parseBackgroundImagePreload}, backgroundImageAliasing:{parser:parseBackgroundImageAliasing}};
        public static const SCALE9_TYPE_STRETCH:String = "stretch";
        public static const SCALE9_TYPE_REPEAT:String = "repeat";
        public static const REPEAT_REPEAT_X:String = "repeat-x";
        public static const REPEAT_REPEAT_Y:String = "repeat-y";
        public static const POSITION_LEFT:String = "left";
        public static const POSITION_RIGHT:String = "right";
        public static const ATTACHMENT_SCROLL:String = "scrollV";
        public static const IMAGE_TYPE_IMAGE:String = "image";

        public static var TRANSITION_SHORTCUTS:Object = {background:["backgroundColor", "backgroundPositionX", "backgroundPositionY"], backgroundPosition:["backgroundPositionX", "backgroundPositionY"], backgroundScale9Rect:["backgroundScale9RectTop", "backgroundScale9RectRight", "backgroundScale9RectBottom", "backgroundScale9RectLeft"], backgroundGradient:["backgroundGradientColors", "backgroundGradientRatios", "backgroundGradientRotation"]};

        public static function parseBackgroundPosition(_arg1:String, _arg2:String):CSSParsingResult{
            var _local3:Object = CSSParsingHelper.removeImportantFlagFromString(_arg1);
            var _local4:String = (_local3.important) ? CSSProperty.IMPORTANT_FLAG : "";
            _arg1 = _local3.result;
            _arg1 = _arg1.split(POSITION_TOP).join("0%").split(POSITION_RIGHT).join("100%").split(POSITION_BOTTOM).join("100%").split(POSITION_LEFT).join("0%");
            var _local5:Array = _arg1.split(" ");
            return (CSSParsingResult.ResultWithPropertiesAndKeys(strToIntProperty((_local5[0] + _local4), _arg2), "backgroundPositionX", strToIntProperty((_local5[1] + _local4), _arg2), "backgroundPositionY"));
        }
        public static function parseBackgroundImagePreload(_arg1:String, _arg2:String):CSSProperty{
            return (strToBoolProperty(_arg1, _arg2, ["preload"]));
        }
        public static function parseBackgroundGradient(_arg1:String, _arg2:String):CSSParsingResult{
            var _local11:String;
            var _local12:String;
            var _local3:Object = CSSParsingHelper.removeImportantFlagFromString(_arg1);
            var _local4:String = (_local3.important) ? CSSProperty.IMPORTANT_FLAG : "";
            _arg1 = _local3.result;
            var _local5:CSSParsingResult = new CSSParsingResult();
            var _local6:Object = StringUtil.sliceStringBetweenMarkers(_arg1, "ratios(", ")", true, true);
            _arg1 = _local6.result;
            var _local7:String = _local6.slice;
            _local6 = StringUtil.sliceStringBetweenMarkers(_arg1, "colors(", ")", true, true);
            _arg1 = _local6.result;
            var _local8:String = _local6.slice;
            var _local9:int;
            var _local10:Array = _arg1.split(" ");
            var _local13:Array = [];
            _local13[GRADIENT_TYPE_LINEAR] = true;
            _local13[GRADIENT_TYPE_RADIAL] = true;
            _local13[GRADIENT_TYPE_NONE] = true;
            _local11 = _local10[_local9];
            _local12 = _local11.toLowerCase();
            if (_local13[_local12]){
                _local5.addPropertyForKey(strToStringProperty((_local12 + _local4), _arg2), "backgroundGradientType");
                ++_local9;
                _local11 = _local10[_local9];
            };
            if (((!((_local11 == null))) && (!(isNaN(parseInt(_local11)))))){
                _local5.addPropertyForKey(strToIntProperty(_local11, _arg2), "backgroundGradientRotation");
                ++_local9;
                _local11 = _local10[_local9];
            };
            if (_local8 != null){
                _local5.addPropertyForKey(parseBackgroundGradientColors((_local8 + _local4), _arg2), "backgroundGradientColors");
            };
            if (_local7 != null){
                _local5.addPropertyForKey(parseBackgroundGradientRatios((_local7 + _local4), _arg2), "backgroundGradientRatios");
            };
            return (_local5);
        }
        public static function parseBackgroundAnimationControl(_arg1:String, _arg2:String):CSSProperty{
            var _local9:Array;
            var _local10:Array;
            var _local11:Object;
            var _local12:int;
            var _local3:Object = strToProperty(_arg1, _arg2);
            var _local4:CSSProperty = _local3.property;
            _arg1 = _local3.filteredString;
            var _local5:RegExp = /\s*(play|stop|loop|marquee)\s*\((.*?)\)/g;
            var _local6:RegExp = /\s*,\s*/;
            var _local7:RegExp = /^\d+$/;
            var _local8:Array = [];
            while (true) {
                _local9 = _local5.exec(_arg1);
                if (!_local9){
                    break;
                };
                _local10 = (_local9[2] as String).split(_local6);
                _local11 = {type:_local9[1], parameters:_local10};
                _local12 = _local10.length;
                while (_local12--) {
                    if (_local7.test(_local10[_local12])){
                        _local10[_local12] = int(parseInt(_local10[_local12]));
                    };
                };
                _local8.push(_local11);
            };
            _local4.setSpecifiedValue(_local8);
            return (_local4);
        }
        public static function parseBackgroundScale9Type(_arg1:String, _arg2:String):CSSProperty{
            if (_arg1 == SCALE9_TYPE_REPEAT){
                return (strToStringProperty(SCALE9_TYPE_REPEAT, _arg2));
            };
            if (_arg1 == SCALE9_TYPE_STRETCH){
                return (strToStringProperty(SCALE9_TYPE_STRETCH, _arg2));
            };
            return (strToStringProperty(SCALE9_TYPE_NONE, _arg2));
        }
        public static function parseBackgroundGradientRatios(_arg1:String, _arg2:String):CSSProperty{
            var _local3:Object = CSSParsingHelper.removeImportantFlagFromString(_arg1);
            _arg1 = _local3.result;
            var _local4:CSSProperty = new CSSProperty();
            _local4.setImportant(_local3.important);
            _local4.setCSSFile(_arg2);
            if (CSSParsingHelper.valueShouldInherit(_arg1)){
                _local4.setInheritsValue(true);
                return (_local4);
            };
            var _local5:Array = _arg1.split(" ");
            var _local6:int;
            while (_local6 < _local5.length) {
                _local5[_local6] = parseInt(_local5[_local6]);
                _local6++;
            };
            _local4.setSpecifiedValue(_local5);
            return (_local4);
        }
        public static function parseBackground(_arg1:String, _arg2:String):CSSParsingResult{
            var _local6:Array;
            var _local3:Object = CSSParsingHelper.removeImportantFlagFromString(_arg1);
            var _local4:String = (_local3.important) ? CSSProperty.IMPORTANT_FLAG : "";
            _arg1 = _local3.result;
            var _local5:CSSParsingResult = new CSSParsingResult();
            _local6 = _arg1.match(CSSParsingHelper.URIExpression);
            if (_local6){
                _local5.addPropertyForKey(strToURLProperty((_local6[0] + _local4), _arg2), "backgroundImage");
                _arg1 = _arg1.split(_local6[0]).join("");
            };
            _local6 = _arg1.match(CSSParsingHelper.colorExpression);
            if (_local6){
                _local5.addPropertyForKey(strToColorProperty((_local6[0] + _local4), _arg2), "backgroundColor");
                _arg1 = _arg1.split(_local6[0]).join("");
            };
            _local6 = _arg1.match(CSSParsingHelper.repeatExpression);
            if (_local6){
                _local5.addPropertyForKey(strToStringProperty((_local6[0] + _local4), _arg2), "backgroundRepeat");
                _arg1 = _arg1.split(_local6[0]).join("");
            };
            _local6 = _arg1.match(CSSParsingHelper.attachmentExpression);
            if (_local6){
                _local5.addPropertyForKey(strToStringProperty((_local6[0] + _local4), _arg2), "backgroundAttachment");
                _arg1 = _arg1.split(_local6[0]).join("");
            };
            _local6 = _arg1.match(CSSParsingHelper.positionExpression);
            if (((_local6) && (_local6[0]))){
                _local5.addEntriesFromResult(parseBackgroundPosition((_local6[0] + _local4), _arg2));
            };
            _local6 = _arg1.match(CSSParsingHelper.preloadExpression);
            if (_local6){
                _local5.addPropertyForKey(parseBackgroundImagePreload((_local6[0] + _local4), _arg2), "backgroundImagePreload");
            };
            return (_local5);
        }
        public static function parseBackgroundImageAliasing(_arg1:String, _arg2:String):CSSProperty{
            return (strToStringProperty(_arg1.toLowerCase(), _arg2));
        }
        public static function parseBackgroundScale9Rect(_arg1:String, _arg2:String):CSSParsingResult{
            return (strToRectParsingResult(_arg1, _arg2, "backgroundScale9Rect", "", strToIntProperty));
        }
        public static function parseBackgroundScale9(_arg1:String, _arg2:String):CSSParsingResult{
            var _local3:Object = CSSParsingHelper.removeImportantFlagFromString(_arg1);
            var _local4:String = (_local3.important) ? CSSProperty.IMPORTANT_FLAG : "";
            _arg1 = _local3.result;
            var _local5:CSSParsingResult = new CSSParsingResult();
            var _local6:Array = [];
            _local6[SCALE9_TYPE_REPEAT] = true;
            _local6[SCALE9_TYPE_STRETCH] = true;
            _local6[SCALE9_TYPE_NONE] = true;
            var _local7:Array = _arg1.split(" ");
            if (_local6[_local7[0]]){
                _local5.addPropertyForKey(parseBackgroundScale9Type((String(_local7.shift()) + _local4), _arg2), "backgroundScale9Type");
            };
            _arg1 = _local7.join(" ");
            _local5.addEntriesFromResult(parseBackgroundScale9Rect(_arg1, _arg2));
            return (_local5);
        }
        public static function parseBackgroundGradientColors(_arg1:String, _arg2:String):CSSProperty{
            var _local3:Object = CSSParsingHelper.removeImportantFlagFromString(_arg1);
            _arg1 = _local3.result;
            var _local4:CSSProperty = new CSSProperty();
            _local4.setImportant(_local3.important);
            _local4.setCSSFile(_arg2);
            if (CSSParsingHelper.valueShouldInherit(_arg1)){
                _local4.setInheritsValue(true);
                return (_local4);
            };
            var _local5:Array = _arg1.split(" ");
            var _local6:int;
            while (_local6 < _local5.length) {
                _local5[_local6] = CSSParsingHelper.parseColor(_local5[_local6]);
                _local6++;
            };
            _local4.setSpecifiedValue(_local5);
            return (_local4);
        }
        public static function parseBackgroundGradientType(_arg1:String, _arg2:String):CSSProperty{
            var _local3:CSSProperty = strToStringProperty(_arg1, _arg2);
            if ((((_local3.specifiedValue() == GRADIENT_TYPE_RADIAL)) || ((_local3.specifiedValue() == GRADIENT_TYPE_LINEAR)))){
                return (_local3);
            };
            return (null);
        }
        public static function parseBackgroundImageType(_arg1:String, _arg2:String):CSSProperty{
            return (strToStringProperty(_arg1.toLowerCase(), _arg2));
        }

    }
}//package reprise.css.propertyparsers 
